import { ElLoading } from 'element-plus';
import { debounce } from 'lodash';

const options = {
    lock: true,
    text: 'Loading……',
    background: 'rgba(0, 0, 0, 0.7)'
};
let loadingInstance;

export const loading = {
    open: function () {
        loadingInstance = ElLoading.service(options);
    },
    close: function () {
        debounce(() => {
            if (loadingInstance) {
                loadingInstance.close();
            }
        }, 300)();
    }
};

const install = function (app) {
    app.config.globalProperties.$loading = loading;
};

export default {
    loading,
    install
};
